package com.dome.client.config.result;

import com.dome.client.config.result.enums.RtnResultCodeEnums;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
public class RtnResultVO<T> implements Serializable {

    /**
     * 返回代码
     */
    private Integer code;

    /**
     * 返回描述信息
     */
    private String msg;


    private T data;

    private RtnResultVO setResultCode(RtnResultCodeEnums code){
        this.code=code.getCode();
        this.msg=code.getMsgCN();
        return this;
    }

    private RtnResultVO setResultMsg(String msg){
        this.msg=msg;
        return this;
    }

    private RtnResultVO setResultCode(RtnResultCodeEnums code, T data){
        this.code=code.getCode();
        this.msg=code.getMsgCN();
        this.data=data;
        return this;
    }

    private static <T>RtnResultVO<T> Default(){
        return new RtnResultVO();
    }

    public static <T>RtnResultVO<T> Success(){
        return Default().setResultCode(RtnResultCodeEnums.SUCCESS);
    }

    public static <T>RtnResultVO<T> Success(String msg, T data){
        return Default().setResultCode(RtnResultCodeEnums.SUCCESS,data).setResultMsg(msg);
    }
    public static <T>RtnResultVO<T> Success(T data){
        return Default().setResultCode(RtnResultCodeEnums.SUCCESS,data);
    }

    public static <T>RtnResultVO<T> Success(RtnResultCodeEnums code, T data){
        return Default().setResultCode(code,data);
    }


    public static <T>RtnResultVO<T> Fail(){
        return Default().setResultCode(RtnResultCodeEnums.FAIL);
    }

    public static <T>RtnResultVO<T> Fail(RtnResultCodeEnums code, T data){
        return Default().setResultCode(code,data);
    }

    public static <T>RtnResultVO<T> Fail(String msg){
        return Default().setResultCode(RtnResultCodeEnums.FAIL).setResultMsg(msg);
    }

    public static <T>RtnResultVO<T> Fail(T data){
        return Default().setResultCode(RtnResultCodeEnums.FAIL,data);
    }

}
